//
//  main.m
//  sa
//
//  Created by mac on 16-5-11.
//  Copyright (c) 2016年 5-10. All rights reserved.
//

//
//  main.m
//  main
//
//  Created by mac on 16-5-10.
//  Copyright (c) 2016年 oyzh. All rights reserved.
//

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[])
{
    
    @autoreleasepool {
        
        // insert code here...
        
        NSString *path=@"/Users/mac/Desktop/00001.vcf";
        NSError *err;
        NSString *str=[[NSString alloc]initWithContentsOfFile:path encoding:NSUTF8StringEncoding error:&err];
        NSArray *arr=[str componentsSeparatedByString:@"\n"];
        NSMutableArray *sz=[NSMutableArray new];
        NSMutableDictionary *dct;
        if (err!=nil) {
            NSLog(@"sasd");
        }
        NSLog(@"%@",str);
        for(NSString *line in arr){
            if ([line hasPrefix:@"BEGIN"]) {
                NSLog(@"这条记录已开始");
                dct=[NSMutableDictionary new];
            }
            if ([line hasPrefix:@"END"]) {
                NSLog(@"这条记录已结速");
                [sz addObject:dct];
            }
            if ([line hasPrefix:@"TEL"]) {
                NSLog(@"找到一条电话记录");
                NSArray *a=[line componentsSeparatedByString:@";"];
                NSString *last=[a lastObject];
                last=[last substringFromIndex:5];
                NSLog(@"a:%@",last);
                dct[@"tel"]=last;
            }
            if ([line hasPrefix:@"FN"]) {
                NSLog(@"找到一条FN 也就是姓名");
                NSArray *name=[ line componentsSeparatedByString:@":"];
                NSString *names=[name lastObject];
                names=[names stringByReplacingOccurrencesOfString:@"=" withString:@"%"];
                names=names.stringByRemovingPercentEncoding;
                NSLog(@"names%@",names);
                dct[@"names"]=names;
            }
        }
        NSLog(@"%@",sz);
        [sz writeToFile:@"/Users/mac/Desktop/master/main/res.txt" atomically:NO];
    }
    return 0;
}

